package com.qqt.csr.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @Author: yang hao
 * @Date: 2024/10/16 17:08
 * @Description: 设备枚举，顺序不要随意变动
 **/
@Getter
public enum DeviceTypeEnum {

    WEB(0, "WEB"),

    ANDROID(1, "ANDROID"),

    IOS(2, "IOS"),

    HARMONYOS(3, "HARMONY"),
    UNKNOWN(99, "unknown"),

    ;

    private final Integer code;

    private final String desc;

    DeviceTypeEnum(final Integer code, final String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static final DeviceTypeEnum[] ENUMS = DeviceTypeEnum.values();

    public static DeviceTypeEnum matchEnum(Integer value) {
        return Arrays.stream(values()).filter(ele -> Objects.equals(ele.code, value)).findFirst().orElse(UNKNOWN);
    }

    public static DeviceTypeEnum matchEnum(String desc) {
        return Arrays.stream(values()).filter(ele -> Objects.equals(ele.desc, desc)).findFirst().orElse(UNKNOWN);
    }

}
